package com.dys.controller;

import com.dys.multiple.DataSource;
import com.dys.multiple.DataSourceType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @className: com.dys.controller.DataSourceController
 * @description: com.dys.controller
 * @author: pine cone
 * @version: v1.0.0
 * @createTime: 2024/11/26 23:24
 */
@RestController
public class DataSourceController {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @GetMapping("/local")
    @DataSource(value = DataSourceType.LOCAL)
    public List<Map<String, Object>> local() {
        List<Map<String, Object>> maps = jdbcTemplate.queryForList("select * from t_emp");
        return maps;
    }

    @GetMapping("/remote")
    @DataSource(value = DataSourceType.REMOTE)
    public List<Map<String, Object>> remote() {
        List<Map<String, Object>> maps = jdbcTemplate.queryForList("select * from sys_user");
        return maps;
    }
}
